<template>
  <div class="modal-overlay" v-if="visible" @click.self="closeModal">
    <div class="modal-content">
      <!-- 关闭按钮 -->
      <button class="close-btn" @click="closeModal">
        <i class="fa fa-times"></i>
      </button>

      <div class="modal-body">
        <!-- 左侧：课程图片 -->
        <div class="course-image-section">
          <div class="image-container">
            <img
                :src="courseData.courseImage || `https://picsum.photos/seed/${courseData.courseId}/400/300`"
                :alt="courseData.courseName"
                class="course-modal-img"
                @load="onImageLoad"
                @error="onImageError"
                :class="{ 'loaded': imageLoaded }"
            />
            <div v-if="!imageLoaded" class="image-placeholder">
              <i class="fa fa-image"></i>
              <span>加载中...</span>
            </div>
          </div>
        </div>

        <!-- 右侧：课程和教练信息 -->
        <div class="course-info-section">
          <!-- 课程基本信息 -->
          <div class="info-group">
            <h2 class="course-title">{{ courseData.courseName }}</h2>
            <div class="course-meta">
              <div class="meta-item">
                <i class="fa fa-clock-o"></i>
                <span>{{ formatCourseTime(courseData.courseTime) }}</span>
              </div>
              <div class="meta-item">
                <i class="fa fa-users"></i>
                <span>已预约: {{ courseData.courseCurrent }}/{{ courseData.courseMax }}</span>
              </div>
              <div class="meta-item">
                <i class="fa fa-signal"></i>
                <span class="grade-badge">{{ courseData.courseGrade }}</span>
              </div>
              <!-- 显示用户等级 -->
              <div class="meta-item" v-if="userLevel">
                <i class="fa fa-user"></i>
                <span>您的等级: <span :class="userLevelClass">{{ userLevel }}</span></span>
              </div>
            </div>
          </div>

          <!-- 课程介绍 -->
          <div class="info-group">
            <h3 class="info-label">
              <i class="fa fa-book"></i> 课程介绍
            </h3>
            <p class="course-intro">{{ courseData.courseIntroduction || '暂无详细介绍' }}</p>
          </div>

          <!-- 教练信息 -->
          <div class="info-group">
            <h3 class="info-label">
              <i class="fa fa-user-circle"></i> 授课教练
            </h3>
            <div class="coach-info">
              <div class="coach-avatar">
                <img
                    :src="courseData.coachImageUrl || `https://picsum.photos/seed/${courseData.coachId}/100/100`"
                    :alt="courseData.coachName"
                    class="coach-img"
                    @load="onCoachImageLoad"
                    @error="onCoachImageError"
                    :class="{ 'loaded': coachImageLoaded }"
                />
                <div v-if="!coachImageLoaded" class="coach-placeholder">
                  <i class="fa fa-user"></i>
                </div>
              </div>
              <div class="coach-details">
                <h4 class="coach-name">{{ courseData.coachName }}</h4>
                <div class="coach-meta">
                  <div class="coach-item">
                    <i class="fa fa-phone"></i>
                    <span>{{ courseData.coachPhone || '暂无电话' }}</span>
                  </div>
                  <div class="coach-item">
                    <i class="fa fa-star"></i>
                    <span>专业: {{ courseData.coachSpecialty || '健身指导' }}</span>
                  </div>
                  <div class="coach-item">
                    <i class="fa fa-trophy"></i>
                    <span>经验: {{ courseData.coachExperience || '5' }}年+</span>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <!-- 预约确认 -->
          <div class="reservation-confirm">
            <h3 class="confirm-title">
              <i class="fa fa-question-circle"></i> 是否要预约此课程？
            </h3>

            <!-- 等级提示信息 -->
            <div v-if="levelCheckMessage" class="level-check-message" :class="levelCheckType">
              <i class="fa" :class="levelCheckIcon"></i>
              {{ levelCheckMessage }}
              <button v-if="showRechargeButton" class="recharge-btn" @click="goToRecharge">
                立即充值
              </button>
            </div>

            <div class="confirm-actions">
              <button
                  class="confirm-btn primary"
                  @click="confirmReservation"
                  :disabled="!courseData.canReserve || !levelCheckPassed"
                  :class="{ 'disabled': !courseData.canReserve || !levelCheckPassed }"
              >
                <i class="fa fa-check"></i>
                {{ levelCheckPassed ? '确认预约' : '无法预约' }}
              </button>
              <button class="confirm-btn secondary" @click="closeModal">
                <i class="fa fa-times"></i>
                取消
              </button>
            </div>

            <div v-if="!courseData.canReserve && levelCheckPassed" class="reservation-tip">
              <i class="fa fa-info-circle"></i>
              当前无法预约该课程（可能已满员或已过期）
            </div>
          </div>
        </div>
      </div>

  <!-- 加载状态 -->
  <div v-if="loading" class="modal-loading">
    <div class="loading-spinner"></div>
    <p>正在加载课程信息...</p>
  </div>
  </div>
  </div>

<!-- 备注输入模态框 -->
<div class="notes-modal-overlay" v-if="showNotesModal" @click.self="closeNotesModal">
  <div class="notes-modal-content">
    <h3 class="notes-modal-title">
      <i class="fa fa-sticky-note"></i> 预约备注
    </h3>
    <div class="notes-input-container">
      <textarea
        v-model="reservationNotes"
        class="notes-textarea"
        placeholder="请输入预约备注（选填）"
        rows="4"
        maxlength="200"
      ></textarea>
      <div class="notes-char-count">{{ reservationNotes.length }}/200</div>
    </div>
    <div class="notes-modal-actions">
      <button class="notes-btn primary" @click="submitNotes">
        <i class="fa fa-check"></i> 确定
      </button>
      <button class="notes-btn secondary" @click="closeNotesModal">
        <i class="fa fa-times"></i> 取消
      </button>
    </div>
  </div>
</div>
</template>

<script setup>
import { ref, reactive, watch, computed, onMounted } from 'vue';
import axios from 'axios';
import { useUserStore } from '@/stores/auth';
import { useRouter } from 'vue-router';

// Props
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  courseId: {
    type: [String, Number],
    default: null
  }
});

// Emits
const emit = defineEmits(['update:visible', 'reservation-success']);

// Store 和 Router
const userStore = useUserStore();
const router = useRouter();

// 响应式数据
const courseData = reactive({
  courseId: null,
  courseName: '',
  courseImage: '',
  courseTime: null,
  courseDuration: 0,
  courseGrade: '',
  courseIntroduction: '',
  courseCurrent: 0,
  courseMax: 0,
  coachId: null,
  coachName: '',
  coachPhone: '',
  coachSpecialty: '',
  coachExperience: 0,
  coachImageUrl: '',
  canReserve: false,
  reservationStatus: ''
});

const loading = ref(false);
const imageLoaded = ref(false);
const coachImageLoaded = ref(false);
const userLevel = ref('');
const userPoints = ref(0);
const levelCheckPassed = ref(false);
const levelCheckMessage = ref('');
const levelCheckType = ref(''); // 'success', 'warning', 'error'
const showRechargeButton = ref(false);
// 备注输入相关状态
const showNotesModal = ref(false);
const reservationNotes = ref('');

// 计算属性
const userLevelClass = computed(() => {
  switch (userLevel.value) {
    case '高级会员':
      return 'level-high';
    case '中级会员':
      return 'level-medium';
    case '初级会员':
      return 'level-low';
    default:
      return 'level-normal';
  }
});

const levelCheckIcon = computed(() => {
  switch (levelCheckType.value) {
    case 'success':
      return 'fa-check-circle';
    case 'warning':
      return 'fa-exclamation-triangle';
    case 'error':
      return 'fa-times-circle';
    default:
      return 'fa-info-circle';
  }
});

// 方法
const closeModal = () => {
  emit('update:visible', false);
  resetData();
};

const resetData = () => {
  Object.assign(courseData, {
    courseId: null,
    courseName: '',
    courseImage: '',
    courseTime: null,
    courseDuration: 0,
    courseGrade: '',
    courseIntroduction: '',
    courseCurrent: 0,
    courseMax: 0,
    coachId: null,
    coachName: '',
    coachPhone: '',
    coachSpecialty: '',
    coachExperience: 0,
    coachImageUrl: '',
    canReserve: false,
    reservationStatus: ''
  });
  imageLoaded.value = false;
  coachImageLoaded.value = false;
  userLevel.value = '';
  userPoints.value = 0;
  levelCheckPassed.value = false;
  levelCheckMessage.value = '';
  levelCheckType.value = '';
  showRechargeButton.value = false;
};

const formatCourseTime = (dateTime) => {
  if (!dateTime) return '';

  try {
    const date = new Date(dateTime);
    if (isNaN(date.getTime())) return dateTime;

    return date.toLocaleString('zh-CN', {
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit',
      weekday: 'long'
    });
  } catch (error) {
    console.error('时间格式化错误:', error);
    return dateTime;
  }
};

const loadCourseReservationInfo = async () => {
  if (!props.courseId) return;

  loading.value = true;
  try {
    const response = await axios.get(`/api/courses/${props.courseId}/reservation-info`);

    // 处理不同的响应格式
    let courseInfo = response.data;
    if (response.data && response.data.data) {
      courseInfo = response.data.data; // 如果返回的是Result格式
    }

    if (courseInfo) {
      Object.assign(courseData, courseInfo);

      // 加载用户等级信息
      await loadUserLevelInfo();
    } else {
      console.error('获取课程预约信息失败：返回数据为空');
      levelCheckMessage.value = '获取课程信息失败';
      levelCheckType.value = 'error';
    }
  } catch (error) {
    console.error('获取课程预约信息失败:', error);
    levelCheckMessage.value = '获取课程信息失败，请稍后重试';
    levelCheckType.value = 'error';
  } finally {
    loading.value = false;
  }
};

const loadUserLevelInfo = async () => {
  // 检查用户登录状态
  if (!userStore.getIsLoggedIn || !userStore.userId) {
    userLevel.value = '未登录';
    levelCheckPassed.value = false;
    levelCheckMessage.value = '请先登录后再预约课程';
    levelCheckType.value = 'error';
    showRechargeButton.value = false;
    return;
  }

  try {
    // 获取用户等级信息 - 尝试多种可能的接口格式
    let userData = null;

    try {
      // 尝试第一种接口格式: /api/users/{userId}
      const userResponse = await axios.get(`/api/users/${userStore.userId}`);
      userData = userResponse.data;
    } catch (error) {
      console.warn('第一种用户接口失败，尝试备用接口:', error);

      // 尝试第二种接口格式: /api/user/info (需要根据实际后端调整)
      try {
        const userResponse = await axios.get('/api/user/info');
        userData = userResponse.data;
      } catch (secondError) {
        console.error('所有用户接口都失败:', secondError);
        throw new Error('无法获取用户信息');
      }
    }

    // 处理不同的响应格式
    let user = null;
    if (userData) {
      if (userData.data) {
        user = userData.data; // Result格式: { data: user }
      } else if (userData.uPoints !== undefined) {
        user = userData; // 直接用户对象
      } else if (userData.user) {
        user = userData.user; // 嵌套格式: { user: ... }
      }
    }

    if (user) {
      // 获取用户积分
      const points = user.uPoints || user.points || 0;
      userPoints.value = points;

      // 计算用户等级
      calculateUserLevel(points);

      // 检查用户等级是否可以预约该课程
      checkUserLevelPermission();
    } else {
      throw new Error('用户数据格式不正确');
    }
  } catch (error) {
    console.error('获取用户等级信息失败:', error);

    // 如果无法获取用户信息，使用默认等级（普通用户）
    userLevel.value = '普通用户';
    userPoints.value = 0;
    checkUserLevelPermission();

    levelCheckMessage.value = '无法获取用户等级信息，使用默认等级';
    levelCheckType.value = 'warning';
  }
};

const calculateUserLevel = (points) => {
  if (points >= 400) {
    userLevel.value = '高级会员';
  } else if (points >= 100) {
    userLevel.value = '中级会员';
  } else if (points >= 1) {
    userLevel.value = '初级会员';
  } else {
    userLevel.value = '普通用户';
  }
};

const checkUserLevelPermission = () => {
  const courseGrade = courseData.courseGrade || '初级';

  // 检查用户等级权限
  switch (userLevel.value) {
    case '高级会员':
      levelCheckPassed.value = true;
      levelCheckMessage.value = `高级会员（${userPoints.value}积分）可以预约所有课程`;
      levelCheckType.value = 'success';
      showRechargeButton.value = false;
      break;
    case '中级会员':
      if (courseGrade === '初级' || courseGrade === '中级') {
        levelCheckPassed.value = true;
        levelCheckMessage.value = `中级会员（${userPoints.value}积分）可以预约初级和中级课程`;
        levelCheckType.value = 'success';
      } else {
        levelCheckPassed.value = false;
        levelCheckMessage.value = `中级会员（${userPoints.value}积分）无法预约高级课程，请充值获取积分提升至高级会员（需400积分）`;
        levelCheckType.value = 'warning';
        showRechargeButton.value = true;
      }
      break;
    case '初级会员':
      if (courseGrade === '初级') {
        levelCheckPassed.value = true;
        levelCheckMessage.value = `初级会员（${userPoints.value}积分）可以预约初级课程`;
        levelCheckType.value = 'success';
      } else {
        levelCheckPassed.value = false;
        levelCheckMessage.value = courseGrade === '中级'
            ? `初级会员（${userPoints.value}积分）无法预约中级课程，请充值获取积分提升至中级会员（需100积分）`
            : `初级会员（${userPoints.value}积分）无法预约高级课程，请充值获取积分提升至高级会员（需400积分）`;
        levelCheckType.value = 'warning';
        showRechargeButton.value = true;
      }
      break;
    case '普通用户':
    default:
      levelCheckPassed.value = false;
      levelCheckMessage.value = `普通用户（${userPoints.value}积分）无法预约课程，请充值获取积分提升用户等级`;
      levelCheckType.value = 'error';
      showRechargeButton.value = true;
      break;
  }
};

// 打开备注输入模态框
const confirmReservation = () => {
  if (!userStore.getIsLoggedIn || !userStore.userId) {
    alert('请先登录后再预约课程');
    return;
  }

  if (!courseData.canReserve) {
    alert('当前无法预约该课程');
    return;
  }

  if (!levelCheckPassed.value) {
    alert(levelCheckMessage.value);
    return;
  }

  // 打开自定义的备注输入模态框
  reservationNotes.value = ''; // 清空之前的输入
  showNotesModal.value = true;
};

// 关闭备注输入模态框
const closeNotesModal = () => {
  showNotesModal.value = false;
};

// 提交备注并执行预约
const submitNotes = async () => {
  try {
    const response = await axios.post('/api/reservations/create', {
      rUId: userStore.userId,
      rCId: courseData.courseId,
      rTId: courseData.coachId,
      rNotes: reservationNotes.value.trim() // 修改为rNotes字段，与后端实体类一致
    });

    // 处理不同的响应格式
    let success = false;
    if (response.data) {
      if (typeof response.data === 'boolean') {
        success = response.data;
      } else if (response.data.success !== undefined) {
        success = response.data.success;
      } else if (response.data.data !== undefined) {
        success = response.data.data;
      } else {
        success = true; // 默认认为成功
      }
    }

    if (success) {
    // 预约成功
    emit('reservation-success');
    closeNotesModal(); // 关闭备注模态框
    closeModal(); // 关闭预约详情模态框
    alert('课程预约成功！');
  } else {
    const errorMsg = response.data?.message || '预约失败，请稍后重试';
    alert(errorMsg);
    closeNotesModal(); // 出错时也关闭备注模态框
  }
  } catch (error) {
    console.error('预约课程失败:', error);
    if (error.response && error.response.data) {
      const errorMsg = error.response.data.message || error.response.data;
      alert(`预约失败: ${errorMsg}`);
    } else {
      alert('预约失败，请稍后重试');
    }
    closeNotesModal(); // 出错时也关闭备注模态框
  }
};

const goToRecharge = () => {
  closeModal();
  // 跳转到充值页面
  router.push('/recharge');
};

// 图片加载处理
const onImageLoad = () => {
  imageLoaded.value = true;
};

const onImageError = () => {
  imageLoaded.value = true;
};

const onCoachImageLoad = () => {
  coachImageLoaded.value = true;
};

const onCoachImageError = () => {
  coachImageLoaded.value = true;
};

// 监听visible和courseId变化
watch(() => props.visible, (newVal) => {
  if (newVal && props.courseId) {
    loadCourseReservationInfo();
  }
});

watch(() => props.courseId, (newVal) => {
  if (props.visible && newVal) {
    loadCourseReservationInfo();
  }
});

// 组件挂载时初始化用户信息（如果已登录）
onMounted(() => {
  if (userStore.isLoggedIn) {
    // 可以预加载用户信息，但不需要等待
    loadUserLevelInfo().catch(console.error);
  }
});
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
  padding: 20px;
}

.modal-content {
  position: relative;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-radius: 16px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
}

/* 备注输入模态框样式 */
.notes-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.notes-modal-content {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: modalSlideIn 0.3s ease-out;
}

.notes-modal-title {
  color: #f8fafc;
  font-size: 1.5rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.notes-input-container {
  margin-bottom: 20px;
  position: relative;
}

.notes-textarea {
  width: 100%;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #f8fafc;
  font-size: 1rem;
  resize: vertical;
  min-height: 100px;
  transition: all 0.3s ease;
}

.notes-textarea:focus {
  outline: none;
  border-color: #f6ad55;
  background: rgba(255, 255, 255, 0.08);
}

.notes-textarea::placeholder {
  color: #94a3b8;
}

.notes-char-count {
  position: absolute;
  bottom: -20px;
  right: 0;
  color: #94a3b8;
  font-size: 0.85rem;
}

.notes-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.notes-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 80px;
  justify-content: center;
}

.notes-btn.primary {
  background: #f6ad55;
  color: #0f172a;
  font-weight: 600;
}

.notes-btn.primary:hover {
  background: #ed8936;
  transform: translateY(-1px);
}

.notes-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
}

.notes-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cbd5e0;
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s;
  backdrop-filter: blur(10px);
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #f8fafc;
  transform: rotate(90deg);
}

.modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-height: 500px;
}

.course-image-section {
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  border-radius: 16px 0 0 16px;
}

.image-container {
  position: relative;
  width: 100%;
  height: 300px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
}

.course-modal-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease;
  opacity: 0;
}

.course-modal-img.loaded {
  opacity: 1;
}

.image-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  color: #94a3b8;
  font-size: 1rem;
}

.image-placeholder i {
  font-size: 3rem;
  margin-bottom: 10px;
  opacity: 0.5;
}

.course-info-section {
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 25px;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 0 16px 16px 0;
}

.info-group {
  animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.course-title {
  font-size: 1.8rem;
  color: #f8fafc;
  margin-bottom: 15px;
  line-height: 1.3;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.course-meta {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cbd5e0;
  font-size: 0.95rem;
}

.meta-item i {
  color: #f6ad55;
  width: 16px;
  text-align: center;
}

.grade-badge {
  padding: 4px 12px;
  background: linear-gradient(135deg, #f6ad55, #ed8936);
  color: white;
  border-radius: 15px;
  font-size: 0.85rem;
  font-weight: 600;
}

.info-label {
  color: #f8fafc;
  margin-bottom: 10px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-label i {
  color: #f6ad55;
}

.course-intro {
  color: #cbd5e0;
  line-height: 1.6;
  font-size: 0.95rem;
  max-height: 80px;
  overflow-y: auto;
}

.coach-info {
  display: flex;
  gap: 15px;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.05);
  padding: 15px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.coach-avatar {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #f6ad55;
  flex-shrink: 0;
}

.coach-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease;
  opacity: 0;
}

.coach-img.loaded {
  opacity: 1;
}

.coach-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  color: #94a3b8;
}

.coach-details {
  flex: 1;
}

.coach-name {
  color: #f8fafc;
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.coach-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.coach-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #cbd5e0;
  font-size: 0.9rem;
}

.coach-item i {
  color: #f6ad55;
  width: 14px;
  text-align: center;
}

.reservation-confirm {
  background: rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: auto;
}

.confirm-title {
  color: #f8fafc;
  margin-bottom: 15px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.confirm-title i {
  color: #f6ad55;
}

/* 等级检查消息样式 */
.level-check-message {
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.level-check-message.success {
  background: rgba(72, 187, 120, 0.1);
  color: #48bb78;
  border: 1px solid rgba(72, 187, 120, 0.3);
}

.level-check-message.warning {
  background: rgba(246, 173, 85, 0.1);
  color: #f6ad55;
  border: 1px solid rgba(246, 173, 85, 0.3);
}

.level-check-message.error {
  background: rgba(245, 101, 101, 0.1);
  color: #f56565;
  border: 1px solid rgba(245, 101, 101, 0.3);
}

.recharge-btn {
  background: linear-gradient(135deg, #f6ad55, #ed8936);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-left: auto;
  transition: all 0.3s;
  white-space: nowrap;
}

.recharge-btn:hover {
  background: linear-gradient(135deg, #ed8936, #dd6b20);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(246, 173, 85, 0.3);
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.confirm-btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.confirm-btn.primary {
  background: linear-gradient(135deg, #48bb78, #38a169);
  color: white;
}

.confirm-btn.primary:hover:not(.disabled) {
  background: linear-gradient(135deg, #38a169, #2f855a);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(72, 187, 120, 0.4);
}

.confirm-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.confirm-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.confirm-btn.disabled {
  background: rgba(255, 255, 255, 0.05);
  color: #94a3b8;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.reservation-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f6ad55;
  font-size: 0.9rem;
}

.modal-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  z-index: 5;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top: 4px solid #f6ad55;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 用户等级样式 */
.level-high {
  color: #f6ad55;
  font-weight: 600;
  text-shadow: 0 0 10px rgba(246, 173, 85, 0.3);
}

.level-medium {
  color: #68d391;
  font-weight: 600;
  text-shadow: 0 0 10px rgba(104, 211, 145, 0.3);
}

.level-low {
  color: #63b3ed;
  font-weight: 600;
  text-shadow: 0 0 10px rgba(99, 179, 237, 0.3);
}

.level-normal {
  color: #cbd5e0;
  font-weight: 600;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .modal-body {
    grid-template-columns: 1fr;
  }

  .course-image-section {
    border-radius: 16px 16px 0 0;
    padding: 20px;
  }

  .course-info-section {
    border-radius: 0 0 16px 16px;
    padding: 20px;
  }

  .image-container {
    height: 200px;
  }

  .course-title {
    font-size: 1.5rem;
  }

  .confirm-actions {
    flex-direction: column;
  }

  .level-check-message {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .recharge-btn {
    margin-left: 0;
    align-self: flex-end;
  }
}

@media (max-width: 480px) {
  .modal-overlay {
    padding: 10px;
  }

  .coach-info {
    flex-direction: column;
    text-align: center;
  }

  .coach-avatar {
    align-self: center;
  }

  .course-meta {
    gap: 8px;
  }

  .meta-item {
    font-size: 0.9rem;
  }
}

/* 滚动条样式 */
.course-intro::-webkit-scrollbar {
  width: 4px;
}

.course-intro::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
}

.course-intro::-webkit-scrollbar-thumb {
  background: #f6ad55;
  border-radius: 2px;
}

.course-intro::-webkit-scrollbar-thumb:hover {
  background: #ed8936;
}
</style>